﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DingHeng.TransportationManagement.Business;
using DingHeng.TransportationManagement.Entity.Constant;
using DingHeng.TransportationManagement.Entity;
using DingHeng.TransportationManagement.WebCommon;
using DingHeng.TransportationManagement.WebCommon.BaseUI;

namespace DingHeng.TransportationManagement.WebSite.Biz
{
    public partial class VehicleDispatchFormPrint : BasePage
    {
        private Guid? VehicleDispatchFormID
        {
            get
            {
                Guid id;
                if (string.IsNullOrEmpty(Request.QueryString.Get("VehicleDispatchFormID")) || Guid.TryParse(Request.QueryString.Get("VehicleDispatchFormID"), out id) == false)
                {
                    return null;
                }
                else
                {
                    return id;
                }
            }
        }
        private void initPage(DingHeng.TransportationManagement.Entity.VehicleDispatchForm VehicleDispatchFormInstance)
        {
            if (VehicleDispatchFormInstance.VehicleID.HasValue)
            {
                VehicleInfo info = new VehicleBiz().LoadByInfoID(VehicleDispatchFormInstance.VehicleID.Value);
                this.lblLicensePlateNo.Text = info.LicensePlateNo;
                this.lblVehicleOwner.Text = info.OwnerName;
                this.lblVehicleCode.Text = info.Code;
            }
            this.lblCode.Text = VehicleDispatchFormInstance.Code;
            this.lblDriverContactNo.Text = VehicleDispatchFormInstance.DriverContactNo;
            this.lblDriver.Text = VehicleDispatchFormInstance.Driver;
            this.lblOwnerContactNo.Text = VehicleDispatchFormInstance.VehicleOwnerContactNo;
            this.lblProjectName.Text = VehicleDispatchFormInstance.ProjectName;
            if (VehicleDispatchFormInstance.PrincipalID.HasValue)
            {
                User user = new UserBiz().LoadById(VehicleDispatchFormInstance.PrincipalID.Value);
                if (user != null)
                {
                    this.lblPricipal.Text = user.Name;
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (VehicleDispatchFormID.HasValue)
                {
                    DingHeng.TransportationManagement.Entity.VehicleDispatchForm VehicleDispatchFormInstance
                         = new VehicleDispatchFormBiz().LoadById(VehicleDispatchFormID.Value);
                    if (VehicleDispatchFormInstance != null
                        && VehicleDispatchFormInstance.Status.HasValue
                        && VehicleDispatchFormInstance.Status.Value == Guid.Parse(StringConstant.StatusCheckIn))
                    {
                        new VehicleDispatchFormBiz().Print(VehicleDispatchFormInstance.ID, WebContext.Current.CurrentUser.Name);
                        initPage(VehicleDispatchFormInstance);
                    }
                    
                }

            }
        }
    }
}